﻿using System;
using System.Collections.Generic;
using System.Text;

using InfoGenerateSystem.Component;
using InfoGenerateSystem.Domain;

namespace InfoGenerateSystem.Service.Implements
{
    /// <summary>
    /// 标签配置保存类
    /// 
    /// 创建人:     王昊
    /// 创建时间:   2009-05-06
    /// 
    /// </summary>
    public class ConfigSaver
    {
        public static void SaveExcelExportConfig(String configFileName, ExcelExportConfig eec, IList<TblbLabel> labelList)
        {
            StringBuilder fileContent = new StringBuilder();
            fileContent.Append("[Config]\r\n");
            fileContent.AppendFormat("RunningState {0}\r\n", eec.RunningState);
            fileContent.AppendFormat("TimerMinutes {0}\r\n", eec.TimerMinutes);
            fileContent.AppendFormat("TimerStart {0}\r\n", eec.TimerStart.ToString("HH:mm"));
            fileContent.Append("[EndConfig]\r\n");

            fileContent.Append("[Labels]\r\n");
            foreach (TblbLabel lbl in labelList)
            {
                fileContent.Append(lbl.SECID);
                fileContent.Append("\r\n");
            }
            fileContent.Append("[EndLabels]");

            FileHelper.WriteFile(configFileName, fileContent.ToString());
        }

        public static void SaveSnagConfig(String configFileName, SnagConfig sc, IList<TblbLabel> labelList, IList<ImageWebPage> webPageList)
        {
            StringBuilder fileContent = new StringBuilder();
            fileContent.Append("[Config]\r\n");
            fileContent.AppendFormat("RunningState {0}\r\n", sc.RunningState);
            fileContent.AppendFormat("TimerMinutes {0}\r\n", sc.TimerMinutes);
            fileContent.AppendFormat("TimerStart {0}\r\n", sc.TimerStart.ToString("HH:mm"));
            fileContent.AppendFormat("SrcWidth {0}\r\n", sc.ScrWidth);
            fileContent.AppendFormat("SrcHeight {0}\r\n", sc.ScrHeight);
            fileContent.AppendFormat("ImageWidth {0}\r\n", sc.ImageWidth);
            fileContent.AppendFormat("ImageHeight {0}\r\n", sc.ImageHeight);
            fileContent.Append("[EndConfig]\r\n");

            fileContent.Append("[Labels]\r\n");
            foreach (TblbLabel lbl in labelList)
            {
                fileContent.Append(lbl.SECID);
                fileContent.Append("\r\n");
            }
            fileContent.Append("[EndLabels]");

            fileContent.Append("[Url]\r\n");
            foreach (ImageWebPage webPage in webPageList)
            {
                fileContent.Append(webPage.Url);
                fileContent.Append("\r\n");
            }
            fileContent.Append("[EndUrl]");

            FileHelper.WriteFile(configFileName, fileContent.ToString());
        }

        public static void SaveExportImageConfig(String configFileName, ExportImageConfig eic, IList<TblbLabel> labelList)
        {
            StringBuilder fileContent = new StringBuilder();
            fileContent.Append("[Config]\r\n");
            fileContent.AppendFormat("RunningState {0}\r\n", eic.RunningState);
            fileContent.AppendFormat("TimerMinutes {0}\r\n", eic.TimerMinutes);
            fileContent.AppendFormat("TimerStart {0}\r\n", eic.TimerStart.ToString("HH:mm"));
            fileContent.AppendFormat("ImagePercent {0}\r\n", eic.ImagePercent);
            fileContent.Append("[EndConfig]\r\n");

            fileContent.Append("[Labels]\r\n");
            foreach (TblbLabel lbl in labelList)
            {
                fileContent.Append(lbl.SECID);
                fileContent.Append("\r\n");
            }
            fileContent.Append("[EndLabels]");

            FileHelper.WriteFile(configFileName, fileContent.ToString());
        }
    }
}
